<!-- TODO -->
<template>
    <div>
        <!-- header -->
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px] mt-[15px]" :inline="true">
                <el-form-item label="地区选择" prop="name">
                    <!-- <el-tree-select
                        :props="{ children: 'children', label: 'label', value: 'value' }"
                        v-model="queryParams.region"
                        :data="arealists"
                        clearable
                        :default-expand-all="false"
                        placeholder="请选择"
                        check-strictly
                    /> -->
                    <el-cascader
                        v-model="queryParams.region"
                        :options="arealists"
                        :show-all-levels="false"
                        :props="{
                            checkStrictly: true,
                            emitPath: false
                        }"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <router-link
                :to="{
                    path: getRoutePath('leader.area/edit:add')
                }"
            >
                <el-button type="primary"> 新增区域 </el-button>
            </router-link>
            <el-table size="large" class="mt-[14px]" :data="pager.lists">
                <el-table-column label="ID" prop="id" />
                <el-table-column label="省市">
                    <template #default="{ row }">
                        {{ row.province_desc + '-' + row.city_desc }}
                    </template>
                </el-table-column>
                <el-table-column label="开通区域" prop="area_desc" />
                <el-table-column label="操作" fixed="right" min-width="160">
                    <template #default="{ row }">
                        <router-link
                            :to="{
                                path: getRoutePath('leader.area/edit:add'),
                                query: {
                                    id: row.id
                                }
                            }"
                        >
                            <el-button type="primary"> 编辑 </el-button>
                        </router-link>
                        <el-button type="primary" @click="handleDelete(row.id)">
                            删除
                        </el-button>
                    </template>
                </el-table-column>
            </el-table>
            <!-- 分页 -->
            <div class="flex justify-end mt-4">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup>
import { usePaging } from '@/hooks/usePaging'
import { areaLists, areaDel, areaRegion } from '@/api/teamhead'
import { getRoutePath } from '@/router'
import feedback from '@/utils/feedback'
import { useDictOptions } from '@/hooks/useDictOptions'
import arealists from '@/utils/area'

const queryParams = reactive({
    region: ''
})
const { pager, getLists, resetPage, resetParams } = usePaging({
    fetchFun: areaLists,
    params: queryParams
})
getLists()
const handleDelete = async (id: any) => {
    await feedback.confirm('确定要删除？')
    await areaDel({ id })
    getLists()
}
//选择框数据

// const { optionsData } = useDictOptions<{
//     arealists: any[]
// }>({
//     arealists: {
//         api: areaRegion
//     }
// })
</script>
<style lang="scss" scope>
//TODO
.el-alert--warning.is-light {
    background-color: rgba(246, 248, 255, 1);
    color: rgba(64, 115, 250, 1);
}
</style>
